// 数据类型定义

// 可视化编辑器类型定义
export interface FlowNode {
  id: string;
  type: 'input' | 'preprocess' | 'operator' | 'merge' | 'output';
  name: string;
  position: { x: number; y: number };
  properties: Record<string, any>;
}

export interface FlowConnection {
  id: string;
  source: string;
  target: string;
  sourceHandle: string;
  targetHandle: string;
}

export interface FlowData {
  nodes: FlowNode[];
  connections: FlowConnection[];
}

export interface FeatureTask {
  id: string;
  name: string;
  type: 'visual' | 'advanced';
  datasetId: string;
  status: 'pending' | 'running' | 'completed' | 'failed';
  progress: number;
  createdAt: string;
  completedAt?: string;
  flowData?: FlowData;
  logs?: string[];
}

export interface Feature {
  id: string;
  name: string;
  type: string;
  description: string;
  minValue?: number;
  maxValue?: number;
  uniqueCount: number;
  nullCount: number;
  exampleValues: (string | number)[];
}

export interface FeatureSet {
  id: string;
  name: string;
  description: string;
  taskId: string;
  featureCount: number;
  recordCount: number;
  createdAt: string;
}

export interface Dataset {
  id: string;
  name: string;
  description: string;
  uploadedAt: string;
  fileSize: number;
  columns: Column[];
  rows: number;
  type?: 'raw' | 'feature'; // 数据集类型：raw-原始数据集，feature-特征集
}

export interface Column {
  name: string;
  type: 'string' | 'number' | 'boolean' | 'date' | 'datetime';
  isSelected: boolean;
  isTarget: boolean;
}

export interface Entity {
  id: string;
  name: string;
  description: string;
  dimensions: string[];
  features: string[];
  datasetId: string;
}

export interface FeatureView {
  id: string;
  name: string;
  description: string;
  entities: string[];
  features: string[];
  createdAt: string;
}

export interface Job {
  id: string;
  name: string;
  type: 'training' | 'evaluation';
  status: 'pending' | 'running' | 'completed' | 'failed' | 'stopped';
  featureViewId: string;
  modelConfig: ModelConfig;
  flowData?: any; // 流程数据
  logs?: string[]; // 日志信息
  createdAt: string;
  updatedAt: string;
  metrics?: Metrics;
}

export interface ModelConfig {
  templateId?: string;
  customScript?: string;
  hyperparameters: Record<string, any>;
  modelType: string;
  baselineModel?: string;
}

export interface Metrics {
  accuracy?: number;
  precision?: number;
  recall?: number;
  f1Score?: number;
  auc?: number;
  loss?: number;
  [key: string]: number | undefined;
}

export interface Model {
  id: string;
  name: string;
  description: string;
  jobId: string;
  createdAt: string;
  metrics: Metrics;
  config: ModelConfig;
  version: number;
}

// UI状态类型
export interface AppState {
  datasets: Dataset[];
  entities: Entity[];
  featureViews: FeatureView[];
  jobs: Job[];
  models: Model[];
  currentStep: 'upload' | 'features' | 'jobs' | 'models' | 'results';
}

// API响应类型
export interface ApiResponse<T> {
  success: boolean;
  data?: T;
  error?: string;
}